#!/bin/bash
# echo the call so we can see what's going on
echo "$0 $1 $2 $3 $4 $5 $6"

# Check syntax
if [ "$1" = "" ]; then
	echo "$0 called without number of histogram for which background variation flag should be changed!"
	exit 0
fi

if [ "$2" = "" ]; then
	echo "$0 called without background refinement flags!"
	exit 0
fi

# Change the flags
echo "k l o b" > temp.txt
echo "g $1 $1" >> temp.txt
echo "$2" >> temp.txt
if [ "$3" == "" ]; then
  echo "No damping flag given, leaving damping untouched..."
else
  echo "Changing damping to $3..."
  echo "d $3" >> temp.txt
fi
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt

expedt `cat GSAS_EXP` < temp.txt

# Test the EXP file
echo "Changed background refinement flags for histogram $1 to \verb=$2=." >> temp.tex
if [ "$3" == "" ]; then
  echo "No damping flag given, leaving damping untouched.\newline"  >> temp.tex
else
  echo "Changing damping to $3.\newline"  >> temp.tex
  echo "d $3" >> temp.txt
fi
